package jmine.tec.test.http;

import java.security.Principal;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import jmine.tec.utils.collection.IteratorEnumeration;

/**
 * @author takeshi
 */
public class MockHttpServletRequest extends MockServletRequest implements HttpServletRequest {

    private String contextPath;

    private Cookie[] cookies;

    private Map<String, String> header = new HashMap<String, String>();

    private String method;

    private String pathInfo, pathTranslated, queryString, remoteUser, requestedSessionId, requestURL, servletPath;

    private HttpSession session = new MockHttpSession();

    /**
     * @return string
     */
    public String getAuthType() {
        return null;
    }

    /**
     * @return the contextPath
     */
    public final String getContextPath() {
        return this.contextPath;
    }

    /**
     * @return the cookies
     */
    public final Cookie[] getCookies() {
        return this.cookies;
    }

    /**
     * @param name string
     * @return long
     */
    public long getDateHeader(final String name) {
        return 0;
    }

    /**
     * @return the header
     */
    public final Map<String, String> getHeader() {
        return this.header;
    }

    /**
     * @param name string
     * @return string
     */
    public String getHeader(final String name) {
        return this.header.get(name);
    }

    /**
     * @return enum
     */
    public Enumeration<String> getHeaderNames() {
        return new IteratorEnumeration<String>(this.header.keySet());
    }

    /**
     * @param name string
     * @return enum
     */
    public Enumeration<String> getHeaders(final String name) {
        return null;
    }

    /**
     * @param name string
     * @return int
     */
    public int getIntHeader(final String name) {
        return Integer.parseInt(this.header.get(name));
    }

    /**
     * @return the method
     */
    public final String getMethod() {
        return this.method;
    }

    /**
     * @return the pathInfo
     */
    public final String getPathInfo() {
        return this.pathInfo;
    }

    /**
     * @return the pathTranslated
     */
    public final String getPathTranslated() {
        return this.pathTranslated;
    }

    /**
     * @return the queryString
     */
    public final String getQueryString() {
        return this.queryString;
    }

    /**
     * @return the remoteUser
     */
    public final String getRemoteUser() {
        return this.remoteUser;
    }

    /**
     * @return the requestedSessionId
     */
    public final String getRequestedSessionId() {
        return this.requestedSessionId;
    }

    /**
     * @return string
     */
    public String getRequestURI() {
        return this.getRequestURL().toString();
    }

    /**
     * @return string
     */
    public StringBuffer getRequestURL() {
        return new StringBuffer(this.requestURL);
    }

    /**
     * @return the servletPath
     */
    public final String getServletPath() {
        return this.servletPath;
    }

    /**
     * @return session
     */
    public HttpSession getSession() {
        return this.session;
    }

    /**
     * @param create boolean
     * @return session
     */
    public HttpSession getSession(final boolean create) {
        if ((this.session == null) && create) {
            this.session = new MockHttpSession();
        }
        return this.session;
    }

    /**
     * @return null
     */
    public Principal getUserPrincipal() {
        return null;
    }

    /**
     * @return null
     */

    public boolean isRequestedSessionIdFromCookie() {
        return false;
    }

    /**
     * @return null
     */

    public boolean isRequestedSessionIdFromUrl() {
        return false;
    }

    /**
     * @return null
     */

    public boolean isRequestedSessionIdFromURL() {
        return false;
    }

    /**
     * @return null
     */

    public boolean isRequestedSessionIdValid() {
        return false;
    }

    /**
     * @param role String
     * @return null
     */

    public boolean isUserInRole(final String role) {
        return false;
    }

    /**
     * @param contextPath the contextPath to set
     */
    public final void setContextPath(final String contextPath) {
        this.contextPath = contextPath;
    }

    /**
     * @param cookies the cookies to set
     */
    public final void setCookies(final Cookie[] cookies) {
        this.cookies = cookies;
    }

    /**
     * @param header the header to set
     */
    public final void setHeader(final Map<String, String> header) {
        this.header = header;
    }

    /**
     * @param method the method to set
     */
    public final void setMethod(final String method) {
        this.method = method;
    }

    /**
     * @param pathInfo the pathInfo to set
     */
    public final void setPathInfo(final String pathInfo) {
        this.pathInfo = pathInfo;
    }

    /**
     * @param pathTranslated the pathTranslated to set
     */
    public final void setPathTranslated(final String pathTranslated) {
        this.pathTranslated = pathTranslated;
    }

    /**
     * @param queryString the queryString to set
     */
    public final void setQueryString(final String queryString) {
        this.queryString = queryString;
    }

    /**
     * @param remoteUser the remoteUser to set
     */
    public final void setRemoteUser(final String remoteUser) {
        this.remoteUser = remoteUser;
    }

    /**
     * @param requestedSessionId the requestedSessionId to set
     */
    public final void setRequestedSessionId(final String requestedSessionId) {
        this.requestedSessionId = requestedSessionId;
    }

    /**
     * @param requestURL the requestURL to set
     */
    public final void setRequestURL(final String requestURL) {
        this.requestURL = requestURL;
    }

    /**
     * @param servletPath the servletPath to set
     */
    public final void setServletPath(final String servletPath) {
        this.servletPath = servletPath;
    }

    /**
     * @param session the session to set
     */
    public final void setSession(final HttpSession session) {
        this.session = session;
    }
}
